<template>
  <div>
      <vxe-modal
          :zIndex="10"
          :showFooter="true"
          :title="
              from == 'edit'
                  ? '编辑发票'
                  : from == 'add'
                  ? '新增发票'
                  : '发票详情'
          "
          ref="modal1"
          :resize="true"
          :fullscreen="true"
          :loading="loading"
          @close="closeBox"
      >
          <div class="flex-app-continer1" style="overflow: auto">
              <div class="info">
                  <div class="info-top">
                      <div class="info-top-l" style="min-width: 600px">
                          <el-row>
                              <el-col :span="8">
                                  <div style="display: inline-flex; align-items: center;height:38px;">
                                      <div
                                          class="radio-tit"
                                          style="line-height: 50%"
                                      >
                                          金额模式：
                                      </div>
                                      <span class="radio-item">
                                          <el-radio
                                              v-model="infoFormData.jems"
                                              label="01"
                                              @click="changeJEMode('01')"
                                          >
                                              不含税
                                          </el-radio>
                                          <el-radio
                                              v-model="infoFormData.jems"
                                              @click="changeJEMode('02')"
                                              label="02"
                                              :disabled="
                                                  infoFormData.cezslxdm ==
                                                      '01' ||
                                                  infoFormData.cezslxdm ==
                                                      '02'
                                              "
                                          >
                                              含税
                                          </el-radio>
                                      </span>
                                  </div>
                              </el-col>
                              <el-col :span="8">
                                  <div
                                      style="
                                          display: inline-flex;
                                          align-items: center;
                                      "
                                  >
                                      <div
                                          class="radio-tit"
                                          style="
                                              line-height: 100%;
                                              width: 70px;
                                          "
                                      >
                                          差额征税：
                                      </div>
                                      <el-select
                                          v-model="infoFormData.cezslxdm"
                                          placeholder="请选择"
                                          size="small"
                                          clearable
                                          style="width: 198px"
                                          :disabled="
                                              infoFormData.tdys == '06'  ||
                                              infoFormData.tdys == '05'  || 
                                              infoFormData.tdys == '09' 

                                          "
                                      >
                                          <el-option
                                              label="全额开票"
                                              value="01"
                                          ></el-option>
                                          <el-option
                                              label="差额开票"
                                              value="02"
                                          ></el-option>
                                      </el-select>
                                  </div>
                              </el-col>
                              <el-col :span="8">
                                  <div
                                      style="
                                          display: inline-flex;
                                          align-items: center;
                                      "
                                  >
                                      <div
                                          class="radio-tit"
                                          style="
                                              line-height: 100%;
                                              width: 120px;
                                              margin-right: 0;
                                              margin-left: 12px;
                                          "
                                      >
                                          购买方是否为自然人：
                                      </div>
                                      <el-select
                                          v-model="infoFormData.gmfsfwzrr"
                                          placeholder="请选择"
                                          size="small"
                                          style="width: 200px"
                                      >
                                          <el-option
                                              v-for="(
                                                  lab, val
                                              ) in gmfsfwzrrList"
                                              :key="lab"
                                              :label="lab"
                                              :value="val"
                                          ></el-option>
                                      </el-select>
                                  </div>
                              </el-col>
                          </el-row>

                          <el-row style="margin: 6px 0">
                              <el-col :span="10" style="max-width: 50%">
                                  <div style="display: inline-flex; align-items: center;">
                                      <div
                                          class="radio-tit"
                                          style="line-height: 50%"
                                      >
                                          <el-select
                                              v-model="infoFormData.dhlx"
                                              placeholder="请选择"
                                              size="small"
                                              style="width: 120px"
                                          >
                                              <el-option
                                                  v-for="(
                                                      lab, val
                                                  ) in toubaodanhaoSelect"
                                                  :key="lab"
                                                  :label="lab"
                                                  :value="val"
                                              ></el-option>
                                          </el-select>
                                      </div>
                                      <div style="margin-right: 20px">
                                          <el-input
                                              style="max-width: 240px"
                                              v-model="infoFormData.dh"
                                              size="small"
                                          ></el-input>
                                      </div>
                                  </div>
                              </el-col>
                              <el-col :span="8">
                                  <div
                                      style="
                                          display: inline-flex;
                                          align-items: center;
                                      "
                                  >
                                      <div
                                          class="radio-tit"
                                          style="
                                              line-height: 100%;
                                              width: 70px;
                                          "
                                      >
                                          特定要素：
                                      </div>
                                      <el-select
                                      clearable
                                          v-model="infoFormData.tdys"
                                          placeholder="请选择"
                                          size="small"
                                          style="max-width: 200px"
                                          @change="changeTDYS"
                                          :disabled="infoFormData.cezslxdm == '02'"
                                      >
                                          <el-option
                                              :disabled="
                                                  !(lab.lxxdm == '06' ||
                                                  lab.lxxdm == '05' ||
                                                  lab.lxxdm == '09'
                                                  )
                                              "
                                              v-for="lab in tedingyaosuSelect"
                                              :key="lab.lxxdm"
                                              :label="lab.lxxmc"
                                              :value="lab.lxxdm"
                                          ></el-option>
                                      </el-select>
                                  </div>
                              </el-col>
                              <el-col :span="4">
                                  <div
                                      style="
                                          margin-left: 12px;
                                          margin-top: 4px;
                                      "
                                  >
                                      <vxe-button
                                          status="primary"
                                          title="展开非必填信息"
                                          icon="fa fa-angle-down"
                                          @click="showInfo()"
                                          style="height: 32px"
                                          v-if="!ifShowInfo"
                                      >
                                          展开非必填信息
                                      </vxe-button>
                                      <vxe-button
                                          status="primary"
                                          title="收起非必填信息"
                                          style="height: 32px"
                                          icon="fa fa-angle-up"
                                          @click="hideInfo()"
                                          v-else
                                      >
                                          收起非必填信息
                                      </vxe-button>
                                  </div>
                              </el-col>
                          </el-row>
                      </div>
                  </div>

                  <!-- 展开信息模块 -->
                  <vxe-form
                      :data="extendFormData"
                      ref="searchForm"
                      size="mini"
                      title-align="right"
                      title-width="200"
                      style="width: 100%"
                      v-show="ifShowInfo"
                  >
                      <vxe-form-item>
                          <template v-slot>
                              <div class="form-tit">业务信息</div>
                          </template>
                      </vxe-form-item>
                      <vxe-form-item
                          title="增值税即征即退代码："
                          :item-render="{}"
                      >
                          <template v-slot>
                              <vxe-select
                                  v-model="extendFormData.zzsjzjtdm"
                                  :placeholder="
                                      from == 'look' ? '' : '请选择'
                                  "
                                  style="width: 220px"
                                  clearable
                                  :disabled="
                                      from == 'red' ||
                                      from == 'look' ||
                                      invoiceCategory.indexOf('red') != -1
                                  "
                              >
                                  <vxe-option
                                      v-for="(item, index) in zzsjzjtDmList"
                                      :key="index"
                                      :value="item.statusType"
                                      :label="item.statusName"
                                  ></vxe-option>
                              </vxe-select>
                          </template>
                      </vxe-form-item>
                      <vxe-form-item
                          title="收购发票类型代码："
                          field="sgfplxdm"
                          :item-render="{}"
                      >
                          <template v-slot>
                              <vxe-select
                                  v-model="extendFormData.sgfplxdm"
                                  :placeholder="
                                      from == 'look' ? '' : '请选择'
                                  "
                                  style="width: 220px"
                                  clearable
                                  :disabled="
                                      from == 'red' ||
                                      from == 'look' ||
                                      invoiceCategory.indexOf('red') != -1
                                  "
                              >
                                  <vxe-option
                                      v-for="(item, index) in sgfplxDmList"
                                      :key="index"
                                      :value="item.statusType"
                                      :label="item.statusName"
                                  ></vxe-option>
                              </vxe-select>
                          </template>
                      </vxe-form-item>
                      <vxe-form-item
                          title="出口业务适用政策代码："
                          field="ckywsyzcdm"
                          :item-render="{}"
                      >
                          <template v-slot>
                              <vxe-select
                                  v-model="extendFormData.ckywsyzcdm"
                                  :placeholder="
                                      from == 'look' ? '' : '请选择'
                                  "
                                  style="width: 220px"
                                  clearable
                                  :disabled="
                                      from == 'red' ||
                                      from == 'look' ||
                                      invoiceCategory.indexOf('red') != -1
                                  "
                              >
                                  <vxe-option
                                      v-for="(item, index) in ckywsyzcDmList"
                                      :key="index"
                                      :value="item.statusType"
                                      :label="item.statusName"
                                  ></vxe-option>
                              </vxe-select>
                          </template>
                      </vxe-form-item>
                      <vxe-form-item>
                          <template v-slot>
                              <div class="form-tit">购买方信息</div>
                          </template>
                      </vxe-form-item>

                      <vxe-form-item title="购买方地址：" field="gmfdz">
                          <template v-slot>
                              <vxe-input
                                  v-model="extendFormData.gmfdz"
                                  :placeholder="
                                      from == 'look' ? '' : '请输入'
                                  "
                                  clearable
                                  maxlength="300"
                                  style="width: 220px"
                                  :disabled="
                                      from == 'red' ||
                                      from == 'look' ||
                                      invoiceCategory.indexOf('red') != -1
                                  "
                              ></vxe-input>
                          </template>
                      </vxe-form-item>
                      <vxe-form-item title="购买方电话：" field="gmfdh">
                          <template v-slot>
                              <vxe-input
                                  v-model="extendFormData.gmfdh"
                                  :placeholder="
                                      from == 'look' ? '' : '请输入'
                                  "
                                  clearable
                                  maxlength="60"
                                  style="width: 220px"
                                  :disabled="
                                      from == 'red' ||
                                      from == 'look' ||
                                      invoiceCategory.indexOf('red') != -1
                                  "
                              ></vxe-input>
                          </template>
                      </vxe-form-item>
                      <vxe-form-item title="银行账号：" field="gmfzh">
                          <template v-slot>
                              <vxe-input
                                  v-model="extendFormData.gmfzh"
                                  :placeholder="
                                      from == 'look' ? '' : '请输入'
                                  "
                                  clearable
                                  maxlength="100"
                                  style="width: 220px"
                                  :disabled="
                                      from == 'red' ||
                                      from == 'look' ||
                                      invoiceCategory.indexOf('red') != -1
                                  "
                              ></vxe-input>
                          </template>
                      </vxe-form-item>
                      <vxe-form-item title="购方开户银行：" :field="extendFormData.sfzsgmfyhzhbq?'gmfkhh':''">
                          <template v-slot>
                            <vxe-input
                                v-model="extendFormData.gmfkhh"
                                :placeholder="
                                    from == 'look' ? '' : '请输入'
                                "
                                clearable
                                maxlength="120"
                                style="width: 150px;margin-right:6px;"
                                :disabled="
                                    from == 'red' ||
                                    from == 'look' ||
                                    invoiceCategory.indexOf('red') != -1
                                "
                            ></vxe-input>
                            <vxe-checkbox v-model="extendFormData.sfzsgmfyhzhbq" content="是否展示"></vxe-checkbox>
                          </template>
                      </vxe-form-item>

                      <vxe-form-item
                          title="购买方经办人姓名："
                          field="gmfjbr"
                      >
                          <template v-slot>
                              <vxe-input
                                  v-model="extendFormData.gmfjbr"
                                  :placeholder="
                                      from == 'look' ? '' : '请输入'
                                  "
                                  clearable
                                  maxlength="150"
                                  style="width: 220px"
                                  :disabled="
                                      from == 'red' ||
                                      from == 'look' ||
                                      invoiceCategory.indexOf('red') != -1
                                  "
                              ></vxe-input>
                          </template>
                      </vxe-form-item>
                      <vxe-form-item
                          title="购买方经办人证件号码："
                          field="jbrsfzjhm"
                      >
                          <template v-slot>
                              <vxe-input
                                  v-model="extendFormData.jbrsfzjhm"
                                  :placeholder="
                                      from == 'look' ? '' : '请输入'
                                  "
                                  clearable
                                  maxlength="30"
                                  style="width: 220px"
                                  :disabled="
                                      from == 'red' ||
                                      from == 'look' ||
                                      invoiceCategory.indexOf('red') != -1
                                  "
                              ></vxe-input>
                          </template>
                      </vxe-form-item>
                      <vxe-form-item
                          title="购买方经办人联系电话："
                          field="gmfjbrlxdh"
                      >
                          <template v-slot>
                              <vxe-input
                                  v-model="extendFormData.gmfjbrlxdh"
                                  :placeholder="
                                      from == 'look' ? '' : '请输入'
                                  "
                                  clearable
                                  maxlength="60"
                                  style="width: 220px"
                                  :disabled="
                                      from == 'red' ||
                                      from == 'look' ||
                                      invoiceCategory.indexOf('red') != -1
                                  "
                              ></vxe-input>
                          </template>
                      </vxe-form-item>
                      <vxe-form-item>
                          <template v-slot>
                              <div class="form-tit">销售方信息</div>
                          </template>
                      </vxe-form-item>

                      <vxe-form-item title="销售方地址：" field="xsfdz">
                          <template v-slot>
                              <vxe-input
                                  v-model="disabledEditForm.xsfdz"
                                  :placeholder="
                                      from == 'look' ? '' : '请输入'
                                  "
                                  clearable
                                  maxlength="26"
                                  style="width: 220px"
                                  :disabled="
                                      from == 'red' ||
                                      from == 'look' ||
                                      invoiceCategory.indexOf('red') != -1
                                  "
                              ></vxe-input>
                          </template>
                      </vxe-form-item>

                      <vxe-form-item title="销售方电话：" field="xsfdh">
                          <template v-slot>
                              <vxe-input
                                  v-model="disabledEditForm.xsfdh"
                                  :placeholder="
                                      from == 'look' ? '' : '请输入'
                                  "
                                  clearable
                                  maxlength="26"
                                  style="width: 220px"
                                  :disabled="
                                      from == 'red' ||
                                      from == 'look' ||
                                      invoiceCategory.indexOf('red') != -1
                                  "
                              ></vxe-input>
                          </template>
                      </vxe-form-item>

                      <vxe-form-item title="银行账号：" field="xsfzh">
                          <template v-slot>
                              <vxe-input
                                  v-model="extendFormData.xsfzh"
                                  :placeholder="
                                      from == 'look' ? '' : '请输入'
                                  "
                                  clearable
                                  maxlength="26"
                                  style="width: 220px"
                                  :disabled="
                                      from == 'red' ||
                                      from == 'look' ||
                                      invoiceCategory.indexOf('red') != -1
                                  "
                              ></vxe-input>
                          </template>
                      </vxe-form-item>

                      <vxe-form-item title="销方开户银行：" >
                          <template v-slot>
                              <vxe-input
                                  v-model="extendFormData.xsfkhh"
                                  :placeholder="
                                      from == 'look' ? '' : '请输入'
                                  "
                                  clearable
                                  maxlength="26"
                                  style="width: 150px;margin-right:6px;"
                                  :disabled="
                                      from == 'red' ||
                                      from == 'look' ||
                                      invoiceCategory.indexOf('red') != -1
                                  "
                              ></vxe-input>

                              <vxe-checkbox v-model="extendFormData.sfzsxsfyhzhbq" content="是否展示"></vxe-checkbox>
                          </template>
                      </vxe-form-item>

                      <vxe-form-item>
                          <template v-slot>
                              <div class="form-tit">收款信息</div>
                          </template>
                      </vxe-form-item>

                      <vxe-form-item title="收款银行名称：" field="skyhmc">
                          <template v-slot>
                              <vxe-input
                                  v-model="extendFormData.skyhmc"
                                  :placeholder="
                                      from == 'look' ? '' : '请输入'
                                  "
                                  clearable
                                  maxlength="120"
                                  style="width: 220px"
                                  :disabled="
                                      from == 'red' ||
                                      from == 'look' ||
                                      invoiceCategory.indexOf('red') != -1
                                  "
                              ></vxe-input>
                          </template>
                      </vxe-form-item>

                      <vxe-form-item title="收款银行账号：" field="skyhzh">
                          <template v-slot>
                              <vxe-input
                                  v-model="extendFormData.skyhzh"
                                  :placeholder="
                                      from == 'look' ? '' : '请输入'
                                  "
                                  clearable
                                  maxlength="100"
                                  style="width: 220px"
                                  :disabled="
                                      from == 'red' ||
                                      from == 'look' ||
                                      invoiceCategory.indexOf('red') != -1
                                  "
                              ></vxe-input>
                          </template>
                      </vxe-form-item>
                      <vxe-form-item title="结算方式：" field="jsfs">
                          <template v-slot>
                              <vxe-select
                                  v-model="extendFormData.jsfs"
                                  :placeholder="
                                      from == 'look' ? '' : '请选择'
                                  "
                                  style="width: 220px"
                                  clearable
                                  :disabled="
                                      from == 'red' ||
                                      from == 'look' ||
                                      invoiceCategory.indexOf('red') != -1
                                  "
                              >
                                  <vxe-option
                                      v-for="(item, index) in jsfsList"
                                      :key="index"
                                      :value="item.statusType"
                                      :label="item.statusName"
                                  ></vxe-option>
                              </vxe-select>
                          </template>
                      </vxe-form-item>

                      <vxe-form-item>
                          <template v-slot>
                              <div class="form-tit">开票人信息</div>
                          </template>
                      </vxe-form-item>
                      <vxe-form-item title="开票人证件号码：" field="kprzjhm">
                          <template v-slot>
                              <vxe-input
                                  v-model="extendFormData.kprzjhm"
                                  :placeholder="
                                      from == 'look' ? '' : '请输入'
                                  "
                                  style="width: 220px"
                                  clearable
                                  maxlength="18"
                                  @change="isCard(extendFormData.kprzjhm)"
                                  :disabled="from == 'look'"
                              ></vxe-input>
                          </template>
                      </vxe-form-item>
                      <vxe-form-item title="开票人证件类型：" field="kprzjlx">
                          <template v-slot>
                              <vxe-select
                                  v-model="extendFormData.kprzjlx"
                                  :placeholder="
                                      from == 'look' ? '' : '请选择'
                                  "
                                  style="width: 220px"
                                  clearable
                                  :disabled="
                                      from == 'red' ||
                                      from == 'look' ||
                                      invoiceCategory.indexOf('red') != -1
                                  "
                              >
                                  <vxe-option
                                      v-for="(item, index) in kprzjlxOption"
                                      :key="index"
                                      :value="item.statusType"
                                      :label="item.statusName"
                                  ></vxe-option>
                              </vxe-select>
                          </template>
                      </vxe-form-item>
                      <vxe-form-item title="收款人：" >
                          <template v-slot>
                              <vxe-input
                                  v-model="extendFormData.skrxm"
                                  placeholder="请输入"
                                  style="width: 220px"
                                  clearable
                                  maxlength="150"
                                  :disabled="from == 'look'"
                              ></vxe-input>
                          </template>
                      </vxe-form-item>
                      <vxe-form-item title="复核人：" >
                          <template v-slot>
                              <vxe-input
                                  v-model="extendFormData.fhrxm"
                                  placeholder="请输入"
                                  style="width: 220px"
                                  clearable
                                  maxlength="75"
                              ></vxe-input>
                          </template>
                      </vxe-form-item>

                      <vxe-form-item>
                          <template v-slot>
                              <div class="form-tit">其他信息</div>
                          </template>
                      </vxe-form-item>
                      <vxe-form-item title="区域代码：" field="qydm">
                          <template v-slot>
                              <vxe-input
                                  v-model="disabledEditForm.qydm"
                                  :placeholder="
                                      from == 'look' ? '' : '请输入'
                                  "
                                  clearable
                                  style="width: 220px"
                                  maxlength="26"
                                  :disabled="
                                      from == 'red' ||
                                      from == 'look' ||
                                      invoiceCategory.indexOf('red') != -1
                                  "
                              ></vxe-input>
                          </template>
                      </vxe-form-item>
                      <vxe-form-item title="应税行为发生地：" field="ysxwfsd">
                          <template v-slot>
                              <vxe-input
                                  v-model="extendFormData.ysxwfsd"
                                  :placeholder="
                                      from == 'look' ? '' : '请输入'
                                  "
                                  clearable
                                  style="width: 220px"
                                  maxlength="11"
                                  :disabled="
                                      from == 'red' ||
                                      from == 'look' ||
                                      invoiceCategory.indexOf('red') != -1
                                  "
                              ></vxe-input>
                          </template>
                      </vxe-form-item>
                  </vxe-form>
                  <!-- 展开模块下面的列表 -->
                  <vxe-button
                      v-show="ifShowInfo"
                      status="primary"
                      type="text"
                      title="增加"
                      icon="fa fa-plus-square-o"
                      @click="addFjys()"
                  >
                      增加特定要素
                  </vxe-button>
                  <vxe-table
                      header-align="center"
                      border
                      :auto-resize="true"
                      :sync-resize="true"
                      ref="xTable2"
                      :data="fjysList"
                      v-show="ifShowInfo"
                      :edit-config="{
                          trigger: 'manual',
                          mode: 'row',
                          showStatus: true,
                      }"
                      class="fj-area"
                  >
                      <vxe-column
                          field="fjysmc"
                          title="附加要素名称"
                          align="center"
                          :edit-render="{}"
                      >
                          <template #edit="{ row }">
                              <vxe-input
                                  v-model="row.fjysmc"
                                  type="text"
                                  maxlength="200"
                                  :disabled="from == 'look'"
                              ></vxe-input>
                          </template>
                      </vxe-column>
                      <vxe-column
                          field="fjyslx"
                          title="附加要素类型"
                          align="center"
                          :edit-render="{}"
                      >
                          <template #edit="{ row }">
                              <vxe-input
                                  v-model="row.fjyslx"
                                  type="text"
                                  maxlength="200"
                                  :disabled="from == 'look'"
                              ></vxe-input>
                          </template>
                      </vxe-column>
                      <vxe-column
                          field="fjysz"
                          title="附加要素值"
                          align="center"
                          :edit-render="{}"
                      >
                          <template #edit="{ row }">
                              <vxe-input
                                  v-model="row.fjysz"
                                  type="text"
                                  maxlength="200"
                                  :disabled="from == 'look'"
                              ></vxe-input>
                          </template>
                      </vxe-column>
                      <vxe-column
                          title="操作"
                          align="center"
                          v-if="from != 'look'"
                      >
                          <template v-slot="scope">
                              <vxe-button
                                  status="primary"
                                  type="text"
                                  title="删除"
                                  icon="fa fa-minus-square-o"
                                  @click="delFjys(scope.row)"
                              >
                                  删除
                              </vxe-button>
                              <vxe-button
                                  status="primary"
                                  type="text"
                                  title="编辑"
                                  icon="fa fa-minus-square-o"
                                  @click="editFjys(scope.row)"
                              >
                                  编辑
                              </vxe-button>
                          </template>
                      </vxe-column>
                  </vxe-table>
              </div>

              <!-- 整体发票区域 -->
              <div class="invoice-area">
                  <div class="box1">
                      <span class="bar-tit">购买方信息</span>
                  </div>
                  <div class="box2">
                      <div class="flex-invoice">
                          <span class="item-tit">名称：</span>
                          <vxe-input
                              v-model="infoFormData.gmfmc"
                              :placeholder="from == 'look' ? '' : '请输入'"
                              clearable
                              maxlength="300"
                              class="input"
                              :disabled="
                                  from == 'look' ||
                                  from == 'red' ||
                                  invoiceCategory.indexOf('red') != -1
                              "
                          ></vxe-input>
                      </div>
                      <div class="flex-invoice">
                          <div class="item-tit" style="margin-top: -21px">
                              纳税人识别号：
                          </div>
                          <vxe-input
                              v-model="infoFormData.gmfnsrsbh"
                              :placeholder="from == 'look' ? '' : '请输入'"
                              clearable
                              maxlength="20"
                              @change="
                                  infoFormData.gmfnsrsbh =
                                      infoFormData.gmfnsrsbh.replace(
                                          /[^0-9A-Z]/g,
                                          ''
                                      )
                              "
                              class="input"
                              :disabled="
                                  from == 'look' ||
                                  from == 'red' ||
                                  invoiceCategory.indexOf('red') != -1
                              "
                          ></vxe-input>
                      </div>
                  </div>
                  <div class="box3">
                      <span class="bar-tit">销售方信息</span>
                  </div>
                  <div class="box4">
                      <div class="flex-invoice">
                          <span class="item-tit">名称：</span>
                          <vxe-input
                              v-model="disabledEditForm.xsfmc"
                              placeholder="请输入"
                              clearable
                              maxlength="300"
                              class="input"
                              disabled
                          ></vxe-input>
                      </div>
                      <div class="flex-invoice">
                          <div class="item-tit" style="margin-top: -21px">
                              纳税人识别号：
                          </div>
                          <vxe-input
                              v-model="disabledEditForm.xsfnsrsbh"
                              placeholder="请输入"
                              clearable
                              maxlength="300"
                              class="input"
                              disabled
                          ></vxe-input>
                      </div>
                  </div>
                  <div class="box5">
                      <div style="white-space: nowrap">
                          <div
                              class="worldBlueBtn"
                              style="margin-left: 12px; height: 20px"
                              @click="insertOneEvent()"
                          >
                              新增行
                          </div>
                          <div
                              class="worldBlueBtn"
                              style="height: 20px"
                              @click="removeEvent()"
                          >
                              删除行
                          </div>
                      </div>
                      <div class="table-area-invoice">
                          <vxe-table
                              :data="tableData"
                              ref="xTable"
                              border="none"
                              show-overflow
                              auto-resize
                              resizable
                              style="overflow: auto; width: 100%"
                              height="240"
                              :edit-config="{
                                  trigger: 'click',
                                  mode: 'row',
                                  showIcon: false,
                                  activeMethod: activeRowMethod,
                              }"
                              @edit-actived="editActivedEvent"
                              @checkbox-change="selectChangeEvent"
                              @cell-click="cellClickEvent"
                              :row-class-name="rowClassName"
                              :cell-style="tableCellStyle"
                              show-footer
                              :footer-cell-class-name="footerCellClassName"
                              :footer-method="footerMethod"
                          >
                              <vxe-column
                                  type="checkbox"
                                  width="60"
                                  v-if="
                                      from != 'red' &&
                                      from != 'look' &&
                                      invoiceCategory.indexOf('red') == -1
                                  "
                              ></vxe-column>

                              <vxe-column
                                  field="xmmc"
                                  title="项目名称"
                                  type="html"
                                  width="170"
                              >
                                  <template v-slot="{ row }">
                                      <div
                                          class="search-box"
                                          @click="goSearchProjectDetail"
                                          key="dis2"
                                      >
                                          <span>{{ row.xmmc }}</span>

                                          <el-button
                                              size="small"
                                              v-if="
                                                  from != 'look' &&
                                                  from != 'red' &&
                                                  invoiceCategory.indexOf(
                                                      'red'
                                                  ) == -1
                                              "
                                          >
                                              <i class="el-icon-search"></i>
                                          </el-button>
                                      </div>
                                  </template>
                              </vxe-column>
                              <vxe-column
                                  field="ggxh"
                                  v-if="isSellAndLeaseOrTrans != 9"
                                  :title="isSellAndLeaseOrTrans ? '产品证书/不动产权证号':'规格型号'"
                                  :edit-render="{}"
                                  :width="isSellAndLeaseOrTrans ?180 :80"
                              >
                                  <template #edit="{ row }">
                                      <vxe-input
                                      v-if='isSellAndLeaseOrTrans === 0'
                                          v-model="row.ggxh"
                                          type="text"
                                          maxlength="150"
                                      ></vxe-input>
                                      <span v-if='isSellAndLeaseOrTrans == 11'>{{ row.ggxh }}</span>
                                  </template>
                              </vxe-column>
                              <vxe-column
                                  field="dw"
                                  v-if="isSellAndLeaseOrTrans != 9"
                                  :title="isSellAndLeaseOrTrans ? '面积单位':'单位'"
                                  :edit-render="{}"
                                  width="80"
                              >
                                  <template #edit="{ row }">
                                    
                                      <vxe-input
                                          v-if='isSellAndLeaseOrTrans === 0'
                                          v-model="row.dw"
                                          type="text"
                                          maxlength="300"
                                      ></vxe-input>
                                      <span v-if='isSellAndLeaseOrTrans == 11'>{{ row.dw }}</span>
                                  </template>
                              </vxe-column>
                              <vxe-column
                                  field="sl"
                                  title="数量"
                                  :edit-render="{}"
                                  width="80"
                              >
                                  <template #edit="{ row }">
                                      <vxe-input
                                          v-model="row.sl"
                                          type="number"
                                          :disabled="amountDisabled"
                                          step="0.000001"
                                          maxlength="25"
                                          @blur="changeAmount(row)"
                                          @change="changeAmountLimit(row)"
                                      ></vxe-input>
                                  </template>
                              </vxe-column>
                              <vxe-column
                                  field="bhsdj"
                                  title="单价(不含税)"
                                  :edit-render="{}"
                                  v-if="infoFormData.jems == '01'"
                                  key="bhsdj"
                                  width="120"
                              >
                                  <template #edit="{ row }">
                                      <vxe-input
                                          v-model="row.bhsdj"
                                          type="number"
                                          :disabled="amountDisabled"
                                          step="0.00000001"
                                          maxlength="25"
                                          @blur="changeDj(row)"
                                          @change="changeDjLimit(row)"
                                      ></vxe-input>
                                  </template>
                              </vxe-column>
                              <vxe-column
                                  field="hsdj"
                                  title="单价(含税)"
                                  :edit-render="{}"
                                  v-else
                                  key="hsdj"
                                  width="100"
                              >
                                  <template #edit="{ row }">
                                      <vxe-input
                                          v-model="row.hsdj"
                                          type="number"
                                          :disabled="amountDisabled"
                                          step="0.00000001"
                                          maxlength="25"
                                          @blur="changeDj(row)"
                                          @change="changeDjLimit(row)"
                                      ></vxe-input>
                                  </template>
                              </vxe-column>

                              <vxe-column
                                  field="bhsje"
                                  title="金额(不含税)"
                                  type="html"
                                  :edit-render="{}"
                                  v-if="infoFormData.cezslxdm == '02'"
                                  key="a"
                                  width="120"
                              >
                                  <template v-slot="{ row }">
                                      <div style="display: flex">
                                          <span
                                              v-if="row.bhsje != ''"
                                              ref="difPrice"
                                          >
                                              {{ row.bhsje }}
                                          </span>
                                          <span v-else>请输入</span>
                                          <!-- <el-button
                                          size='small'
                                          @click="addPrice(row)"
                                          v-if="from != 'look'"
                                          style="margin-left: 6px;"
                                      >
                                          <i class="el-icon-search"></i>
                                      </el-button> -->
                                          <vxe-button
                                              size="mini"
                                              @click="addPrice(row)"
                                              v-if="from != 'look'"
                                              style="margin-left: 6px"
                                          >
                                              <i class="vxe-icon--search"></i>
                                          </vxe-button>
                                      </div>
                                  </template>
                              </vxe-column>
                              <vxe-column
                                  field="bhsje"
                                  title="金额(不含税)"
                                  :edit-render="{}"
                                  v-else-if="infoFormData.jems == '01'"
                                  key="b"
                                  width="120"
                              >
                                  <template #edit="{ row }">
                                      <vxe-input
                                          v-model="row.bhsje"
                                          type="number"
                                          :disabled="amountDisabled"
                                          step="0.01"
                                          @blur="changePrice(row)"
                                          @input="changePriceLimit(row)"
                                      ></vxe-input>
                                  </template>
                              </vxe-column>
                              <vxe-column
                                  field="hsje"
                                  title="金额(含税)"
                                  :edit-render="{}"
                                  v-else
                                  key="c"
                                  width="100"
                              >
                                  <template #edit="{ row }">
                                      <vxe-input
                                          v-model="row.hsje"
                                          type="number"
                                          :disabled="amountDisabled"
                                          step="0.01"
                                          @blur="changePrice(row)"
                                          @input="changePriceLimit(row)"
                                      ></vxe-input>
                                  </template>
                              </vxe-column>
                              <vxe-column
                                  field="slv"
                                  title="税率/征收率"
                                  width="120"
                                  type="html"
                                  :edit-render="{}"
                              >
                                  <template v-slot="{ row }">
                                      <!-- rowIndex -->
                                      <div>
                                          <span v-if="row.yhzcbs == '03' || row.yhzcbs == '04'">{{ (row.yhzcbs == '03' && '***') || row.yhzcbs == '04' && '' }}</span>
                                          <span v-else>{{ addDW(row.slv) }}</span>
                                          <span>{{  }}</span>
                                          <!-- <i v-show="(row.slv || row.slv=== 0) && (infoFormData.cezslxdm != '02' || (tableData[rowIndex]&&tableData[rowIndex].kce ))" class="el-icon-edit"  
                                      style="cursor: pointer;width:16px;height:16px;font-size:16px !important;margin-left:3px;"
                                      :style="{
                                          color: (row.slv || row.slv == 0)? '#606266': 'red'
                                      }"
                                      @click="changeRate(row)"
                                          ></i> -->
                                      </div>
                                  </template>
                              </vxe-column>
                              <vxe-column field="se" title="税额" width="80">
                                  <template #edit="{ row }">
                                      <vxe-input
                                          v-model="row.se"
                                          type="text"
                                      ></vxe-input>
                                  </template>
                              </vxe-column>
                          </vxe-table>
                      </div>
                  </div>
                  <div class="box6">价税合计（大写）</div>
                  <div class="box7">
                      <vxe-button
                          status="primary"
                          type="text"
                          icon="fa fa-times-circle-o"
                          style="flex: 1; color: #222; text-align: left"
                      >
                          {{
                              infoFormData.jems == '01'
                                  ? changeMoneyToChinese(
                                        Math.abs(
                                            Number(
                                                (totalbhsN + seN).toFixed(2)
                                            )
                                        ),
                                        '元'
                                    )
                                  : changeMoneyToChinese(
                                        Math.abs(Number(totalhsN.toFixed(2))),
                                        '元'
                                    )
                          }}
                      </vxe-button>
                      <span class="total-tit">（小写）</span>
                      <div class="total-val">
                          ￥{{
                              infoFormData.jems == '01'
                                  ? Number(
                                        (totalbhsN + seN).toFixed(2)
                                    ).toLocaleString()
                                  : Number(
                                        totalhsN.toFixed(2)
                                    ).toLocaleString()
                          }}
                      </div>
                  </div>
                  <div class="boxSevenPointfive">
                      <component :is="componentSelect" ref="componentSelectRef" :vmsManualTdywDtoList="vmsManualTdywDtoList" @editMJAndCQZS="editMJAndCQZS"></component>

                  </div>
                  <div class="box8" :style=bzHeight><span class="bar-tit">备注</span></div>
                  <div class="box9" :style=bzHeight>
                      <p
                          style="margin-left: 12px;height: 20px;    white-space: normal;"
                          v-if="this.infoFormData.cezslxdm == '02'"
                      >
                          扣除额: {{ tableData[0] && tableData[0].kce }}
                      </p>

                     


                      <el-row v-show="this.extendFormData.sfzsgmfyhzhbq">
                          <el-col :span="12">
                            <p
                              style="margin-left: 12px;height: 20px;    white-space: normal;"
                            >
                                购买方账号: {{ this.extendFormData.gmfzh }}
                            </p>
                          </el-col>
                          <el-col :span="12">
                              <p style="height: 20px;    white-space: normal;"
                              >
                                    购买方开户行： {{ this.extendFormData.gmfkhh }}
                              </p>
                          </el-col>
                      </el-row>
                      <el-row v-show="this.extendFormData.sfzsxsfyhzhbq">
                          <el-col :span="12">
                            <p
                              style="margin-left: 12px;height: 20px;    white-space: normal;"
                            >
                                销售方账号： {{this.extendFormData.xsfzh}}
                            </p>
                          </el-col>
                          <el-col :span="12">
                              <p style="height: 20px;    white-space: normal;"
                              >
                                  销售方开户行： {{this.extendFormData.xsfkhh}}
                              </p>
                          </el-col>
                      </el-row>
                      <el-row v-show="extendFormData.skrxm || extendFormData.fhrxm">
                          <el-col :span="12">
                            <p
                              style="margin-left: 12px;height: 20px;    white-space: normal;"
                            >
                              收款人： {{ extendFormData.skrxm }}
                            </p>
                          </el-col>
                          <el-col :span="12">
                              <p style="height: 20px;    white-space: normal;"
                              >
                              复核人： {{ extendFormData.fhrxm}}
                              </p>
                          </el-col>
                      </el-row>

                      <vxe-textarea
                          v-model="infoFormData.bz"
                          :placeholder="from == 'look' ? '' : '请输入'"
                          class="text-area"
                          resize="none"
                          style="color: #bb8c91; border: none; height: 100%"
                          maxlength="450"
                          :disabled="from == 'look'"
                      ></vxe-textarea>
                  </div>
                  <div class="man-area">
                      <span class="man-input">开票人：</span>
                      <vxe-input
                          v-model="disabledEditForm.kpr"
                          maxlength="300"
                          :disabled="true"
                      ></vxe-input>
                  </div>
              </div>

              <div class="amount-layer" id="layer1">
                  <projectListComp
                      @selected="selected"
                      ref="projectListComp"
                  />
              </div>
              <div class="amount-layer" id="layer3">
                  <differentPriceComp
                      @added="added"
                      ref="differentPriceComp"
                  />
              </div>
              <div class="amount-layer" id="layer4">
                  <selectRateComp
                      @changedRate="changedRate"
                      ref="selectRateComp"
                  />
              </div>
          </div>
          <template v-slot:footer>
              <vxe-button @click="closeBox" status="info">
                  {{ from == 'red' ? '上一步' : '取消' }}
              </vxe-button>
              <vxe-button
                  @click="submitRedBox"
                  status="primary"
                  v-if="
                      from == 'red' ||
                      (invoiceCategory.indexOf('red') != -1 && from != 'look')
                  "
              >
                  <!-- 红色票的保存 -->
                  保存
              </vxe-button>
              <vxe-button
                  @click="save"
                  status="primary"
                  v-else-if="from != 'look'"
              >
                  保存
              </vxe-button>
          </template>
      </vxe-modal>

      <vxe-modal v-model="msgShow" width="60%" @close="msgDialogFn">
          <template v-slot>
              <div
                  style="
                      max-height: 100vh;
                      overflow-y: auto;
                      overflow-x: hidden;
                  "
              >
                  <div v-for="(msg, index) in messageDialog" :key="index">
                      {{ msg }}
                  </div>
              </div>
          </template>
      </vxe-modal>
  </div>
</template>
<script>
import { mixin, mixinVariable } from '@/utils/mixin.js'
import VXETable from 'vxe-table'
import {
  checkAndSave,
  updateInvoice,
  getDefBIzdictByLxdm,
} from '@/api/vmsClassifyCode.js'
import projectListComp from './projectListComp'
import differentPriceComp from './differentPriceComp'
import selectRateComp from './selectRateComp'
import leaseHouse from './bzForm/leaseHouse.vue'
import sellHouse from './bzForm/sellHouse.vue'
import transportation from './bzForm/transportation.vue'
import { cloneDeep } from 'lodash'

export default {
  name: 'realMakeInvoiceComp',
  mixins: [mixin, mixinVariable],
  data() {
      return {
            vmsManualTdywDtoList:[],
          tedingyaosuSelect: [],
          msgShow: false,
          messageDialog: [],

          lzfpbz: this.invoiceCategory.indexOf('red') != -1 ? 'N' : 'Y', //蓝字发票标志
          delRows: [],
          billCode: '',
          maxId: 0,
          curRowIndex: -1,
          autoSize: true,
          selectedRow: [],
          amountDisabled: false,

          // base
          infoFormData: {
              jems: '01',
              cezslxdm: '',
              gmfsfwzrr: '02',
              dhlx: '',
              dh: '',
              tdys: '',

              gmfmc: '',
              gmfnsrsbh: '',

              gmfdz: '',
              gmfdh: '',
              gmfkhh: '',
              gmfzh: '',
              gmfjbr: '',
              jbrsfzjhm: '',
              gmfjbrlxdh: '',
              xsfdz: '',
              xsfdh: '',
              xsfkhh: '', //
              xsfzh: '', //
              skyhmc: '',
              skyhzh: '', //
              jsfs: '', //
              kprzjhm: '', //
              qyDm: '', //

              xsfmc: '', //
              bz: '', //
          },
          // 拓展
          extendFormData: {
              zzsjzjtdm: '', //
              sgfplxdm: '', //
              ckywsyzcdm: '', //
              gmfdz: '', //
              gmfdh: '', //
              gmfzh: '', //
              gmfkhh: '', //
              sfzsgmfyhzhbq: '', //
              gmfjbr: '', //
              jbrsfzjhm: '', //
              gmfjbrlxdh: '', //

              xsfdz: '', //
              xsfdh: '', //
              xsfzh: '', //
              xsfkhh: '', //
              sfzsxsfyhzhbq: '', //

              skyhmc: '', //
              skyhzh: '', //
              jsfs: '', //
              kprzjhm: '', //
              kprzjlx: '', //
              fhrxm: '', //
              skrxm: '', //

              qydm: '', //
              ysxwfsd: '', //
          },
          // 完成
          fjysList: [],

          tableData: [],
          disabledEditForm: {
              xsfmc: '',
              xsfdz: '',
              xsfdh: '',
              xsfnsrsbh: '',
              xsfzh: '',
              xsfkhh: '',
              sfzsxsfyhzhbq: '',
              qydm: '',
              hydm: '',
              kpr: '',
          },

          rateTypeArr: [],
          ifShowInfo: false, //
          totalbhsN: 0, //
          totalhsN: 0, //
          totalbhs: 0, //
          totalhs: 0, //
          totalbhsStr: '', //
          totalhsStr: '', //
          seN: 0, //
          from: '',
          loading: false,
          isSellAndLeaseOrTrans: 0
      }
  },
  props: {
      invoiceCategory: '',
  },
  computed:{
      bzHeight(){
          return {
              height: this.infoFormData.cezslxdm == '02' && '100px'
          }
      },
      componentSelect(){
          let selectCom = '';
          if(this.infoFormData.tdys == '06'){
              selectCom = 'leaseHouse'
          }else if(this.infoFormData.tdys == '05'){
              selectCom = 'sellHouse'
          }else if(this.infoFormData.tdys == '09'){
              selectCom = 'transportation'
          }
          return selectCom
      }
  },
  watch: {
      'infoFormData.cezslxdm': {
          handler(val) {
              if (val) {
                  this.infoFormData.jems = '01'
              }
          },
      },
      'infoFormData.tdys': { // 5销售 6租赁 9旅客运输
          handler(val) {
              if (val == '06' || val == '05' ) {
                  this.infoFormData.cezslxdm = ''
                  this.isSellAndLeaseOrTrans = 11
                  if(this.tableData.length >=1){
                      this.tableData = this.tableData.slice(0,0)
                  }
                //   this.vmsManualTdywDtoList = []
              }else if (val == '09' ) {
                  this.infoFormData.cezslxdm = ''
                  this.isSellAndLeaseOrTrans = 9
                  if(this.tableData.length >=1){
                      this.tableData = this.tableData.slice(0,0)
                  }

              }else{
                this.isSellAndLeaseOrTrans = 0;
              }
          },
      },
  },
  created() {
      this.getDict()
  },
  components: {
      projectListComp,
      differentPriceComp,
      selectRateComp,
      leaseHouse,
      sellHouse,
      transportation,
  },
  methods: {
    changeTDYS(){
        this.vmsManualTdywDtoList = []
    },
    editMJAndCQZS(data){
        setTimeout(()=>{
            if(this.tableData&&this.tableData[0]){
                this.$set(this.tableData,0,{
                    ...this.tableData[0],
                    ...data
                })
            }else{
                this.$errorRef.open({
                    isShow:true,
                    contentArray: [
                        {
                            value: '请先选择项目。'
                        }
                    ]
                })
            }
        },500)

    },
      isCard(card) {
          if (card.length == 18 || card.length == 15) {
              var reg = /(^\d{15}$)|(^\d{18}$)|(^\d{17}(\d|X|x)$)/
              if (reg.test(card) === false) {
                  this.$message.error('请输入正确的身份证号')
                  this.extendFormData.kprzjhm = ''
              }
          }
      },
      getDict() {
          getDefBIzdictByLxdm({
              lxdm: 'VMS_TDYSBQGL',
          }).then(
              ({ data }) => {
              },
              (err) => {}
          )
      },
      msgDialogFn() {
          this.msgShow = false
          this.messageDialog = []
      },
      addDetailCopy() {
          this.disabledEditForm = {
              xsfmc: this.$store.state.invoice2.newInvoiceInfo.xsfmc,
              xsfdz: this.$store.state.invoice2.newInvoiceInfo.xsfdz,
              xsfnsrsbh: this.$store.state.invoice2.newInvoiceInfo.xsfnsrsbh, //
              qydm: this.$store.state.invoice2.newInvoiceInfo.qydm,
              xsfzh: this.$store.state.invoice2.newInvoiceInfo.xsfzh,
              xsfkhh: this.$store.state.invoice2.newInvoiceInfo.xsfkhh,
              sfzsxsfyhzhbq: this.$store.state.invoice2.newInvoiceInfo.sfzsxsfyhzhbq || '',
              hydm: this.$store.state.invoice2.newInvoiceInfo.hydm,
              kpr: this.$store.state.invoice2.newInvoiceInfo.kpr, //
              xsfdh: this.$store.state.invoice2.newInvoiceInfo.xsfdh,
          }

          this.extendFormData.xsfzh = this.$store.state.invoice2.newInvoiceInfo.xsfzh
          this.extendFormData.xsfkhh = this.$store.state.invoice2.newInvoiceInfo.xsfkhh
      },
      addFjys() {
          this.fjysList.push({
              fjysmc: '',
              fjyslx: '',
              fjysz: '',
          })
      },
      editFjys(row) {
          this.$refs.xTable2.setActiveCell(row, 'fjyslx')
          this.$refs.xTable2.setActiveCell(row, 'fjysmc')
          this.$refs.xTable2.setActiveCell(row, 'fjysz')
      },
      async delFjys(row) {
          this.$alert('您确定要删除选中的数据吗？', '删除', {
              confirmButtonText: '确定',
              callback: (action) => {
                  if (action == 'confirm') {
                      const $table = this.$refs.xTable2
                      let ind = $table.getRowIndex(row)
                      this.fjysList.splice(ind, 1)
                  } else {
                      this.$message({
                          type: 'success',
                          message: `取消删除`,
                      })
                  }
              },
          })
      },
      activeRowMethod({ row, rowIndex }) {
          let r = true
          if (
              this.from == 'red' ||
              this.from == 'look' ||
              this.invoiceCategory.indexOf('red') != -1
          ) {
              r = false
          } else {
              r = true
          }
          return r
      },
      resetData() {
          // 整体表单
          this.infoFormData = {
              jems: '01', //
              cezslxdm: '', //
              gmfsfwzrr: '02', //
              dhlx: '', //
              dh: '', //
              tdys: '', //

              gmfmc: '', //
              gmfnsrsbh: '', ///

              // xsfmc: //
              // xsfnsrsbh: '',
              fppz: this.$store.state.invoice2.busData.fppz,

              gmfdz: '', //
              gmfdh: '', //
              gmfkhh: '', //
              gmfzh: '', //
              gmfjbr: '', //
              jbrsfzjhm: '', //
              gmfjbrlxdh: '', //
              xsfdz: '', //
              xsfdh: '', //
              xsfkhh: '', //
              xsfzh: '', //
              skyhmc: '', //
              skyhzh: '', //
              jsfs: '', //
              kprzjhm: '', //
              qyDm: '', //

              xsfmc: '', //
              bz: '', //
          }
          this.extendFormData = {
              zzsjzjtdm: '', //
              sgfplxdm: '', //
              ckywsyzcdm: '', //
              gmfdz: '', //
              gmfdh: '', //
              gmfzh: '', //
              gmfkhh: '', //
              sfzsgmfyhzhbq: '', //
              gmfjbr: '', //
              jbrsfzjhm: '', //
              gmfjbrlxdh: '', //

              xsfdz: '', //
              xsfdh: '', //
              xsfzh: '', //
              xsfkhh: '', //
              sfzsxsfyhzhbq: '', //

              skyhmc: '', //
              skyhzh: '', //
              jsfs: '', //
              kprzjhm: '', //
              kprzjlx: '', //
              fhrxm: '', //
              skrxm: '', //

              qydm: '', //
              ysxwfsd: '', //
          }

          this.fjysList = []
          this.tableData = []

          this.delRows = []
          this.billCode = '' //
          this.maxId = 0 //
          this.curRowIndex = -1 //
          this.selectedRow = []
          this.amountDisabled = false
          this.rateTypeArr = []
          this.ifShowInfo = false
          this.totalbhsN = 0
          this.totalhsN = 0
          this.totalbhs = 0
          this.totalhs = 0
          this.totalbhsStr = ''
          this.totalhsStr = ''
          this.seN = 0
      },
      changeMoneyToChinese(money, currencyunit) {
          if (currencyunit == '万元' || currencyunit == '万元/亩') {
              money = (money * 10000).toFixed(6)
          }
          let cnNums = new Array(
              '零',
              '壹',
              '贰',
              '叁',
              '肆',
              '伍',
              '陆',
              '柒',
              '捌',
              '玖'
          )
          let cnIntRadice = new Array('', '拾', '佰', '仟') //
          let cnIntUnits = new Array('', '万', '亿', '兆') //
          let cnDecUnits = new Array('角', '分', '毫', '厘') //
          let cnInteger = '整' //
          let cnIntLast = '元' //
          let IntegerNum //
          let DecimalNum //
          let DecimalStr = '' //
          // end
          let ChineseStr = '' //

          let parts //

          if (money == '') {
              return ''
          }
          money = parseFloat(money)
          if (money == 0) {
              ChineseStr = cnNums[0] + cnIntLast + cnInteger
              if (currencyunit == '万元/亩') {
                  ChineseStr = ChineseStr + '每亩'
              }
              return ChineseStr
          }
          money = money.toString() //
          if (money.indexOf('.') == -1) {
              IntegerNum = money
              DecimalNum = ''
          } else {
              parts = money.split('.')
              IntegerNum = parts[0]
              DecimalNum = parts[1].substr(0, 4)
          }
          if (parseInt(IntegerNum, 10) > 0) {
              let zeroCount = 0
              let IntLen = IntegerNum.length
              let n, p, q, m, i
              for (i = 0; i < IntLen; i++) {
                  n = IntegerNum.substr(i, 1)
                  p = IntLen - i - 1
                  q = p / 4
                  m = p % 4
                  if (n == '0') {
                      zeroCount++
                  } else {
                      if (zeroCount > 0) {
                          ChineseStr += cnNums[0]
                      }
                      zeroCount = 0 // 归零
                      ChineseStr += cnNums[parseInt(n)] + cnIntRadice[m]
                  }
                  if (m == 0 && zeroCount < 4) {
                      ChineseStr += cnIntUnits[q]
                  }
              }
              ChineseStr += cnIntLast
          }

          if (DecimalNum != '') {
              let decLen = DecimalNum.length
              let n, i
              for (i = 0; i < decLen; i++) {
                  n = DecimalNum.substr(i, 1)
                  if (n != '0') {
                      DecimalStr += cnNums[Number(n)] + cnDecUnits[i]
                  }
              }
          }

          if (DecimalStr == '') {
              ChineseStr += cnInteger
          } else {
              ChineseStr += DecimalStr
          }
          // end

          if (ChineseStr == '') {
              ChineseStr += cnNums[0] + cnIntLast + cnInteger
          }
          if (currencyunit == '万元/亩') {
              ChineseStr = ChineseStr + '每亩'
          }
          return ChineseStr
      },
      errorMessage(val) {
          if (val) {
              if (typeof val === 'number') {
                  val = val.toString()
              }
              try {
                  if (val.split('.')[0].length >= 16) {
                      VXETable.modal.message({
                          content: '金额超出税局要求，请核实或进行拆分处理！',
                          status: 'error',
                      })
                      return true
                  }
              } catch (error) {}
          } else {
              return false
          }
      },
      limitPoint(str, len) {
          try {
              if (str) {
                  let poiVal = str.split('.')
                  let left = poiVal[0]
                  let r = poiVal[1]
                  if (r && r.length > len) {
                      let r1 = r.substring(0, len)
                      str = `${left}.${r1}`
                  }
                  return str
              } else {
                  return str
              }
          } catch (error) {
              return str
          }
      },
      changeAmount(row) {
          if (this.infoFormData.cezslxdm != '') {
              if (
                  typeof row.bhsje != 'undefined' &&
                  row.bhsje != '' &&
                  row.bhsje != null &&
                  row.sl != 0
              ) {
                  let bhsje = Number(row.bhsje)
                  let sl = Number(row.sl)
                  row.bhsdj = (bhsje / sl).toFixed(6)
              }
          } else if (
              typeof row.bhsdj != 'undefined' &&
              row.bhsdj != null &&
              row.bhsdj != ''
          ) {
              let bhsdj = Number(row.bhsdj)
              let sl = Number(row.sl)
              let hsdj = Number(row.hsdj)
              let slv = Number(row.slv)
              if (
                  this.errorMessage(bhsdj * sl) ||
                  this.errorMessage(hsdj * sl)
              ) {
                  return
              }
              row.bhsje = (bhsdj * sl).toFixed(2)
              row.hsje = (hsdj * sl).toFixed(2)
              row.se = (bhsdj * sl * slv).toFixed(2)
          }
          // 修改自己
          try {
              let slnew = isNaN(Number(row.sl).toFixed(6))
                  ? row.sl
                  : Number(row.sl).toFixed(6)
              row.sl = slnew
          } catch (err) {
              console.log(err)
          }

          // try {
          //     if(row.sl){
          //         if(isNaN(Number(row.sl).toFixed(6))){

          //         }else{
          //             row.sl = parseFloat(Number(row.sl).toFixed(6))
          //         }

          //     }
          // } catch (error) {

          // }
          // this.$refs.xTable.updateData()
      },
      changeAmountLimit(row) {
          try {
              if (row.sl) {
                  if (isNaN(Number(row.sl).toFixed(6))) {
                  } else {
                      row.sl = this.limitPoint(row.sl, 6)
                  }
              }
          } catch (error) {}
          this.$refs.xTable.updateData()
      },
      changeDj(row) {
          if (typeof row.slv == 'undefined' || row.slv == null) {
              VXETable.modal.message({
                  content: '请点击搜索图标，先选择项目！',
                  status: 'error',
              })
              return
          }
          if (this.infoFormData.jems == '01') {
              //
              let bhsdj = Number(row.bhsdj)
              let slv = Number(row.slv)
              row.hsdj = (bhsdj * (1 + slv)).toFixed(6)
          } else {
              let hsdj = Number(row.hsdj)
              let slv = Number(row.slv)
              row.bhsdj = (hsdj / (1 + slv)).toFixed(6)
          }
          if (this.infoFormData.cezslxdm != '') {
              if (
                  typeof row.bhsje != 'undefined' &&
                  row.bhsje != '' &&
                  row.bhsje != null &&
                  row.bhsdj != 0
              ) {
                  let bhsje = Number(row.bhsje)
                  let bhsdj = Number(row.bhsdj)
                  row.sl = (bhsje / bhsdj).toFixed(6)
              }
          } else if (
              typeof row.sl != 'undefined' &&
              row.sl != '' &&
              row.sl != null
          ) {
              let bhsdj = Number(row.bhsdj)
              let sl = Number(row.sl)
              let hsdj = Number(row.hsdj)
              let slv = Number(row.slv)

              if (
                  this.errorMessage((bhsdj * sl).toFixed(6)) ||
                  this.errorMessage((hsdj * sl).toFixed(2))
              ) {
                  return
              }
              row.bhsje = (bhsdj * sl).toFixed(2)
              row.hsje = (hsdj * sl).toFixed(2)
              row.se = (bhsdj * sl * slv).toFixed(2)
          }

          // 修改自己
          try {
              let slnew = isNaN(Number(row.bhsdj).toFixed(6))
                  ? row.bhsdj
                  : Number(row.bhsdj).toFixed(6)
              row.bhsdj = slnew
          } catch (err) {
              console.log(err)
          }
          try {
              let slnew = isNaN(Number(row.hsdj).toFixed(6))
                  ? row.hsdj
                  : Number(row.hsdj).toFixed(6)
              row.hsdj = slnew
          } catch (err) {
              console.log(err)
          }
      },
      changeDjLimit(row) {
          try {
              if (row.bhsdj) {
                  if (isNaN(Number(row.bhsdj).toFixed(6))) {
                  } else {
                      row.bhsdj = this.limitPoint(row.bhsdj, 6)
                  }
              }
              if (row.hsdj) {
                  if (isNaN(Number(row.hsdj).toFixed(6))) {
                  } else {
                      row.hsdj = this.limitPoint(row.hsdj, 6)
                  }
              }
          } catch (error) {}
          this.$refs.xTable.updateData()
      },
      changePrice(row) {
          if (typeof row.slv == 'undefined' || row.slv == null) {
              VXETable.modal.message({
                  content: '请点击搜索图标，先选择项目！',
                  status: 'error',
              })
              return
          }
          if (this.errorMessage(row.bhsje) || this.errorMessage(row.hsje)) {
              return
          }
          if (this.infoFormData.jems == '01') {
              //不含税
              let bhsje = Number(row.bhsje)
              let slv = Number(row.slv)
              row.hsje = (bhsje * (1 + slv)).toFixed(2)
              row.se = (bhsje * slv).toFixed(2)
          } else {
              let hsje = Number(row.hsje)
              let slv = Number(row.slv)
              row.bhsje = (hsje / (1 + slv)).toFixed(2)
              row.se = ((hsje * slv) / (1 + slv)).toFixed(2)
          }

          // 有数量
          if (
              typeof row.sl != 'undefined' &&
              row.sl != '' &&
              row.sl != null &&
              row.sl != 0
          ) {
              let bhsje = Number(row.bhsje)
              let sl = Number(row.sl)
              let hsje = Number(row.hsje)
              row.bhsdj = (bhsje / sl).toFixed(6)
              row.hsdj = (hsje / sl).toFixed(6)
          } else if (
              // 有单价
              typeof row.bhsdj != 'undefined' &&
              row.bhsdj != '' &&
              row.bhsdj != null &&
              row.bhsdj != 0 &&
              typeof row.hsdj != 'undefined' &&
              row.hsdj != '' &&
              row.hsdj != null &&
              row.hsdj != 0
          ) {
              let bhsje = Number(row.bhsje)
              let hsje = Number(row.hsje)
              let bhsdj = Number(row.bhsdj)
              let hsdj = Number(row.hsdj)
              if (this.infoFormData.jems == '01') {
                  row.sl = (bhsje / bhsdj).toFixed(6)
              } else {
                  row.sl = (hsje / hsdj).toFixed(6)
              }
          }

          // 修改自己
          try {
              let slnew = isNaN(Number(row.bhsje).toFixed(2))
                  ? row.bhsje
                  : Number(row.bhsje).toFixed(2)
              row.bhsje = slnew
          } catch (err) {
              console.log(err)
          }
          try {
              let slnew = isNaN(Number(row.hsje).toFixed(6))
                  ? row.hsje
                  : Number(row.hsje).toFixed(6)
              row.hsje = slnew
          } catch (err) {
              console.log(err)
          }
      },
      changePriceLimit(row) {
          try {
              if (row.bhsje) {
                  if (isNaN(Number(row.bhsje).toFixed(2))) {
                  } else {
                      row.bhsje = this.limitPoint(row.bhsje, 2)
                  }
              }
              if (row.hsje) {
                  if (isNaN(Number(row.hsje).toFixed(2))) {
                  } else {
                      row.hsje = this.limitPoint(row.hsje, 2)
                  }
              }
          } catch (error) {}
          this.$refs.xTable.updateData()
      },

      changeRateType(e) {
          let len = this.rateTypeArr.length
          let typePre = len == 0 ? '' : this.rateTypeArr[len - 1]
          let typeCurrent = e.value == null ? '' : e.value
          this.rateTypeArr.push(typeCurrent)
          if (typeCurrent == '01' && this.infoFormData.jems == '02') {
              this.infoFormData.cezslxdm = typePre
              this.rateTypeArr.pop()
              VXETable.modal.message({
                  content:
                      '差额开票的金额模式仅支持不含税模式，请修改金额模式为不含税！',
                  status: 'error',
              })
          } else if (typeCurrent == 1 && this.tableData.length > 0) {
              this.infoFormData.cezslxdm = typePre
              this.rateTypeArr.pop()
              VXETable.modal.message({
                  content: '若需切换差额开票，请删除已有发票明细行后重试！',
                  status: 'error',
              })
          } else if (typePre == 1 && this.tableData.length > 0) {
              if (typeCurrent == '' || typeCurrent == null) {
                  this.infoFormData.cezslxdm = ''
              } else {
                  this.infoFormData.cezslxdm = typePre
              }
              this.rateTypeArr.pop()
              VXETable.modal.message({
                  content: '若需切换差额开票，请删除已有发票明细行后重试！',
                  status: 'error',
              })
          }
      },
      changeJEMode(e) {
          if (
              this.from == 'red' ||
              this.from == 'look' ||
              this.invoiceCategory.indexOf('red') != -1
          ) {
              return
          }
          let t = e + ''
          this.infoFormData.jems = t
          if (t == '2' && this.infoFormData.cezslxdm == '02') {
              //含税
              this.infoFormData.jems = '01'
              VXETable.modal.message({
                  content:
                      '差额开票的金额模式仅支持不含税模式，请先修改差额征税类型！',
                  status: 'error',
              })
          }
      },

      added(d) {
          let k = this
          let amount = d.newAmount
          let kce = d.kce
          let idx = this.curRowIndex
          this.tableData[idx].bhsje = amount
          this.tableData[idx].kce = kce
          // this.tableData[idx].se = (amount * this.tableData[idx].slv).toFixed(
          //     2
          // )
          this.tableData[idx].se = (d.jshj - amount).toFixed(2)
          if (
              typeof this.tableData[idx].sl != 'undefined' &&
              this.tableData[idx].sl != null &&
              this.tableData[idx].sl != 0
          ) {
              this.tableData[idx].bhsdj =
                  this.tableData[idx].bhsje / this.tableData[idx].sl
          }
          this.$refs.xTable.updateData()
      },
      addPrice(row) {
          if (typeof row.slv == 'undefined' || row.slv == null) {
              VXETable.modal.message({
                  content: '请点击搜索图标，先选择项目！',
                  status: 'error',
              })
              return
          }
          this.$refs.differentPriceComp.show(row)
      },
      changeRate(row) {
          if (
              typeof row.slv === 'undefined' ||
              row.slv === null ||
              row.slv === ''
          ) {
              VXETable.modal.message({
                  content: '请点击搜索图标，先选择项目！',
                  status: 'error',
              })
              return
          }
          this.$refs.selectRateComp.show(row)
      },
      showInfo() {
          this.ifShowInfo = true
      },
      hideInfo() {
          this.ifShowInfo = false
      },
      selected(data) {
          let rowData = data.row
          let idx = this.curRowIndex

          this.tableData[idx].jsff = rowData.jsff // 计税方法 删掉笔以后行间加
          this.tableData[idx].zsxm = rowData.zsxm // 征税项目 删掉笔以后行间加
          this.tableData[idx].yhzcbs = rowData.yhzcbs // 征税项目 删掉笔以后行间加
          this.tableData[idx].dw = rowData.jldwText // 计量单位 删掉笔以后行间加

          this.tableData[idx].xmmc = data.pname
          this.tableData[idx].slv = this.delDW(rowData.zzssl)
          this.tableData[idx].slvStr = rowData.zzssl
          this.tableData[idx].sphfwmc = rowData.sphfwmc //
          this.tableData[idx].sphfwfljc = rowData.sphfwfljc //
          this.tableData[idx].zzstsgl = rowData.yhzcbs //
          this.tableData[idx].sphfwssflhbbm = rowData.gstcmCode //-----
          this.tableData[idx].jzjt = '01' //
          this.tableData[idx].yhzcbs = rowData.yhzcbs //
          this.tableData[idx].ProjectRow = rowData //、
          
          // 原本点必修改后处理，现在改成只是初始化数量，单价，金额
          this.tableData[idx].bhsdj = ''
          this.tableData[idx].bhsje = ''
          this.tableData[idx].hsdj = ''
          this.tableData[idx].hsje = ''
          this.tableData[idx].se = ''
          this.tableData[idx].sl = ''

      },
      // selected(data) {
      //     let rowData = data.row
      //     let idx = this.curRowIndex

      //     this.tableData[idx].xmmc = data.pname
      //     this.tableData[idx].slv = this.delDW(rowData.zsl)
      //     this.tableData[idx].slvStr = rowData.slv
      //     this.tableData[idx].sphfwmc = rowData.sphfwmc //
      //     this.tableData[idx].sphfwfljc = rowData.sphfwfljc //
      //     this.tableData[idx].tdyslxdm = rowData.tdyslxdm //----
      //     this.tableData[idx].zzstsgl = rowData.yhzcbs //
      //     this.tableData[idx].sphfwssflhbbm = rowData.sphfwssflhbbm //-----
      //     this.tableData[idx].jzjt = '01' //
      //     this.tableData[idx].yhzcbs = rowData.yhzcbs //
      //     this.tableData[idx].ProjectRow = rowData //
      //     if (data.selectSource == '2') {
      //         //选择的是产品信息
      //         this.tableData[idx].productCode = rowData.productCode //
      //         this.tableData[idx].productName = rowData.productName //
      //         this.tableData[idx].dw = rowData.dw //
      //         this.tableData[idx].fpspdj = rowData.fpspdj //
      //         this.tableData[idx].ggxh = rowData.ggxh //
      //     }
      // },
      changedRate(data) {
          let rowData = data.formdata
          let idx = this.curRowIndex

          this.tableData[idx].jsff = rowData.jsff //
          this.tableData[idx].zsxm = rowData.zsxm //
          this.tableData[idx].slv = this.delDW(rowData.slv) //
          this.tableData[idx].jzjt = rowData.jzjt //
          this.tableData[idx].sfyz = rowData.sfyz //
          this.tableData[idx].yzllx = rowData.yzllx //
          this.tableData[idx].zcbkdk = rowData.zcbkdk //
          this.tableData[idx].lslbs = rowData.lslbs //
          this.tableData[idx].yhzcbs = rowData.yhzcbs //
          this.tableData[idx].yhzcbs = rowData.yhzcbs //

          let bhsje = Number(this.tableData[idx].bhsje)
          let slv = this.tableData[idx].slv

          if (this.infoFormData.cezslxdm == '02') {
              let jsje = bhsje + +this.tableData[idx].se
              let taxAmount = jsje
              let minusAmount = this.tableData[idx].kce
              let se = ((taxAmount - minusAmount) * slv) / (1 + slv)
              this.tableData[idx].bhsje = (jsje - se).toFixed(2)

              this.tableData[idx].bhsdj = (
                  this.tableData[idx].bhsje / (this.tableData[idx].sl || 1)
              ).toFixed(2)
              let seRes = se.toFixed(2)
              this.tableData[idx].se = seRes
          } else {
              this.tableData[idx].se = (bhsje * slv).toFixed(2) //
          }
          this.$refs.xTable.updateData()
      },
      delDW(val) {
          if (val.includes('%')) {
              val = val.split('%')[0] / 100
          }
          let res = Number(val)
          return res
      },
      addDW(val) {
          if ((val != '' && val != null && val != undefined) || val === 0) {
              try {
                  val = val * 100 + '%'
                  return val
              } catch (error) {}
          }
          return val
      },
      goSearchProjectDetail() {
          if (
              this.from == 'look' ||
              this.from == 'red' ||
              this.invoiceCategory.indexOf('red') != -1
          ) {
              return
          }
          this.$refs.projectListComp.show(this.infoFormData)
      },
      footerCellClassName({ $rowIndex, column, columnIndex }) {
          if (columnIndex === 0) {
              if ($rowIndex === 0) {
                  return 'col-red'
              } else {
                  return ''
              }
          }
      },
      tableCellStyle({ row, column, rowIndex, columnIndex }) {
          let rowStyle = {}
          if (
              (columnIndex == 1 ||
                  columnIndex == 2 ||
                  columnIndex == 3 ||
                  columnIndex == 4 ||
                  columnIndex == 5 ||
                  columnIndex == 6 ||
                  columnIndex == 7) &&
              this.from != 'look' &&
              this.from != 'red' &&
              this.invoiceCategory.indexOf('red') == -1
          ) {
              rowStyle = {
                  background: '#e6f7f7',
                  border: '1px solid #dcdfe6',
                  'border-left': 'none',
              }
          } else if (
              columnIndex == 0 &&
              this.from != 'red' &&
              this.from != 'look' &&
              this.invoiceCategory.indexOf('red') == -1
          ) {
              rowStyle.background = '#fff'
              rowStyle = {
                  background: '#fff',
                  'border-right': '1px solid #dcdfe6',
              }
          } else {
              rowStyle = {
                  background: '#EEEEEE',
                  border: '1px solid #dcdfe6',
                  'border-left': 'none',
              }
          }
          return rowStyle
      },
      rowClassName({ row }) {
          return 'row'
      },
      sumNum(list, field) {
          let count = 0
          list.forEach((item) => {
              count += Number(item[field])
          })
          let n = count.toFixed(2)
          let n1 = Number(n).toLocaleString()
          let obj = {
              number: Number(n),
              numberStr: n1,
          }
          if (
              Number.isNaN(obj.number) ||
              obj.number === 'NaN' ||
              obj.numberStr === '0.00'
          ) {
              obj.number = 0
          }
          if (
              Number.isNaN(obj.numberStr) ||
              obj.numberStr === 'NaN' ||
              obj.numberStr === '0.00'
          ) {
              obj.numberStr = 0
          }
          return obj
      },
      footerMethod({ columns, data }) {
          let k = this
          const footerData = [
              columns.map((column, _columnIndex) => {
                  if (_columnIndex === 0) {
                      return '合计'
                  }
                  if (['bhsje', 'hsje', 'se'].includes(column.property)) {
                      let tmp = this.sumNum(data, column.property)

                      let tmpNumber = tmp.numberStr

                      if (column.property == 'hsje') {
                          k.totalhs = tmpNumber
                          k.totalhsN = tmp.number
                      }
                      if (column.property == 'bhsje') {
                          k.totalbhs = tmpNumber
                          k.totalbhsN = tmp.number
                      }
                      if (column.property == 'se') {
                          k.seN = tmp.number
                      }

                      return tmp.numberStr
                  }
                  return null
              }),
          ]
          return footerData
      },
      selectChangeEvent({ row, rowIndex, checked }) {
          if (row.rowStatus == 'newRow') {
              return
          }
          if (checked) {
              this.selectedRow.push(rowIndex)
          } else {
          }
      },
      cellClickEvent({ row, rowIndex }) {
          this.curRowIndex = rowIndex
      },
      editActivedEvent({ rowIndex, row }) {
          this.amountDisabled = row.rowStatus === 'newRow'
      },
      async insertNewRowEvent(r, record) {
          let k = this
          const $table = this.$refs.xTable
          $table.insertAt(record, r).then(({ row }) => {
              let t = $table.getTableData()
              k.tableData = t.tableData
          })
      },
      insertOneEvent() {
          if (
              this.infoFormData.cezslxdm == '02' &&
              this.tableData.length > 0
          ) {
              VXETable.modal.message({
                  content: '差额征税开票只能添加一条项目数据',
                  status: 'error',
              })
              return
          }
          if (
              this.infoFormData.tdys == '05' &&
              this.tableData.length > 0
          ) {
              VXETable.modal.message({
                  content: '不动产销售发票仅支持单行开具！',
                  status: 'error',
              })
              return
          }
          if (
              this.infoFormData.tdys == '06' &&
              this.tableData.length > 0
          ) {
              VXETable.modal.message({
                  content: '不动产租赁发票仅支持单行开具！',
                  status: 'error',
              })
              return
          }
          if (
              this.infoFormData.tdys == '09' &&
              this.tableData.length > 0
          ) {
              VXETable.modal.message({
                  content: '旅客运输服务发票仅支持单行开具！',
                  status: 'error',
              })
              return
          }
          if (this.tableData.length >= 2000) {
              VXETable.modal.message({
                  content: '发票明显不能超过2000行',
                  status: 'error',
              })
              return
          }
          const $table = this.$refs.xTable
          let record = {
              uuid: this.maxId,
              rowStatus: 'normalRow',
              bhsdj: '',
              hsdj: '',
              bhsje: '',
              hsje: '',
              se: '',
              xmmc: '',
              ggxh: '',
              dw: '',
              sl: '',
          }
          this.insertNewRowEvent(-1, record)
          this.maxId = this.maxId + 1
          $table.clearCheckboxRow()
          this.selectedRow = []
      },
      resetRowStatus() {
          let k = this
          const $table = this.$refs.xTable
          let t = $table.getTableData()
          let d = t.tableData
          for (let i = 0; i < d.length; i++) {
              if (d[i].rowStatus == 'discountedRow') {
                  let idx = k.getChildIdx(d[i].uuid)
                  if (idx == -1) {
                      d[i].rowStatus = ''
                  }
              }
          }
          k.tableData = d
      },
      getChildIdx(rowId) {
          const $table = this.$refs.xTable
          let t = $table.getTableData()
          let d = t.tableData
          let idx = -1
          for (let i = 0; i < d.length; i++) {
              if (d[i].pid == rowId) {
                  idx = i
              }
          }
          return idx
      },
      getIdx(rowId) {
          const $table = this.$refs.xTable
          let t = $table.getTableData()
          let d = t.tableData
          let idx = -1
          for (let i = 0; i < d.length; i++) {
              if (d[i].uuid == rowId) {
                  idx = i
              }
          }
          return idx
      },
      async removeEvent() {
          let k = this
          const $table = this.$refs.xTable
          const selectRecords = $table.getCheckboxRecords()
          let flag = false
          let idx = -1
          let arr = []
          for (let i = 0; i < selectRecords.length; i++) {
              if (selectRecords[i].rowStatus == 'discountedRow') {
                  idx = this.getChildIdx(selectRecords[i].uuid)
                  if (idx != -1) {
                      arr.push(this.tableData[idx])
                  }
              }
          }
          if (arr.length > 0) {
              $table.setCheckboxRow(arr, true)
          }
          const newSelectRecords = $table.getCheckboxRecords()
          if (selectRecords.length) {
              if (newSelectRecords.length == selectRecords.length) {
                  this.$alert('您确定要删除选中的数据吗？', '删除', {
                      confirmButtonText: '确定',
                      callback: (action) => {
                          if (action == 'confirm') {
                              $table.removeCheckboxRow().then(({ row }) => {
                                  let t = $table.getTableData()
                                  k.tableData = t.tableData
                                  k.resetRowStatus()
                                  this.$message({
                                      type: 'success',
                                      message: `删除成功`,
                                  })
                              })
                          } else {
                              this.$message({
                                  type: 'success',
                                  message: `取消删除`,
                              })
                          }
                      },
                  })
              }
          } else {
              VXETable.modal.message({
                  content: '请至少选择一条数据',
                  status: 'error',
              })
          }
      },

      $setLoading(val) {
          this.loading = val || false
      },
      async save() {
          let k = this;



          if (k.infoFormData.gmfmc.trim() == '') {
              VXETable.modal.message({
                  content: '购买方信息名称不能为空',
                  status: 'error',
              })
              return
          } else if (
              this.infoFormData.cezslxdm == '02' &&
              this.tableData &&
              this.tableData.length >= 2
          ) {
              //差额
              VXETable.modal.message({
                  content: '差额征税开票只能添加一条项目数据',
                  status: 'error',
              })
              return
          } else {
              let msg = ''
              const $table = this.$refs.xTable
              let d = $table.getTableData().tableData
              if (d.length == 0)
                  return VXETable.modal.message({
                      content: '请选择项目',
                      status: 'error',
                  })
              let idx = 0
              let jzjt = d.length > 0 ? d[0].jzjt : ''

              for (let i = 0; i < d.length; i++) {
                  if (
                      (d[i].xmmc == null || d[i].xmmc.trim() == '') &&
                      d[i].rowStatus != 'newRow'
                  ) {
                      idx = i + 1
                      msg = '发票项目明细第' + idx + '条项目名称不能为空！'
                      break
                  }
                  let p = k.infoFormData.jems == '01' ? d[i].bhsje : d[i].hsje
                  if (p == null || p == '') {
                      idx = i + 1
                      msg = '发票项目明细第' + idx + '条金额不能为空！'
                      break
                  }

                  let dj =
                      k.infoFormData.jems == '01' ? d[i].bhsdj : d[i].hsdj
                  dj = dj == null ? '' : dj
                  let sl = d[i].sl == null ? '' : d[i].sl
                  if ((sl == '' && dj == '') || (sl != '' && dj != '')) {
                  } else {
                      idx = i + 1
                      msg =
                          '发票项目明细第' +
                          idx +
                          '条数量、单价同时填写或都不填写！'
                      break
                  }

                  // if (
                  //     (d[i].jsff == null || d[i].jsff.trim() == '') &&
                  //     d[i].rowStatus != 'newRow'
                  // ) {
                  //     idx = i + 1
                  //     msg = '发票项目明细第' + idx + '条补充信息需要填写！'
                  //     break
                  // } else if (
                  //     (d[i].zsxm == null || d[i].zsxm.trim() == '') &&
                  //     d[i].rowStatus != 'newRow'
                  // ) {
                  //     idx = i + 1
                  //     msg = '发票项目明细第' + idx + '条补充信息需要填写！'
                  //     break
                  // } else if (
                  //     (d[i].slv === null ||
                  //         d[i].slv === '' ||
                  //         d[i].slv === undefined) &&
                  //     d[i].rowStatus != 'newRow'
                  // ) {
                  //     idx = i + 1
                  //     msg = '发票项目明细第' + idx + '条补充信息需要填写！'
                  //     break
                  // }
              }

              if (msg != '') {
                  VXETable.modal.message({ content: msg, status: 'error' })
                  return
              }
          }

          if(this.extendFormData.sfzsgmfyhzhbq){
            if( !this.extendFormData.gmfzh){
              return   VXETable.modal.message({
                  content: '购买方账号,不得为空！',
                  status: 'error',
              })
            }
            if( !this.extendFormData.gmfkhh ){
              return               VXETable.modal.message({
                  content: '购买方开户行,不得为空！',
                  status: 'error',
              })
            }
          }
          if(this.extendFormData.sfzsxsfyhzhbq){
            if( !this.extendFormData.xsfzh){
              return               VXETable.modal.message({
                  content: '销售方账号,不得为空！',
                  status: 'error',
              })
            }
            if( !this.extendFormData.xsfkhh ){
              return               VXETable.modal.message({
                  content: '销售方开户行,不得为空！',
                  status: 'error',
              })
            }
          }

          if(this.$refs.componentSelectRef){
              let isCon  = await this.$refs.componentSelectRef.submitValidate();
              if(isCon){
                  this.saveTest()
              }
              return
          }else{
              this.saveTest() //
          }
      },
      saveTest() {
          let k = this
          this.$setLoading(true)
          // 1111


          let obj2 = {
              vmsManualAddDtoList: this.fjysList,
              vmsManualBaseDto: {
                  ...this.infoFormData,
                  applyId:
                      this.$store.state.invoice2.invoinceFormStart1.busId,

                  hjje:
                      this.infoFormData.jems == '01'
                          ? this.totalbhsN
                          : this.totalhsN,
                  hjse: this.seN,
                  jshj:
                      (this.infoFormData.jems == '01'
                          ? this.totalbhsN
                          : this.totalhsN) + this.seN,
                  fppz: this.$store.state.invoice2.busData.fppz,
              },
              vmsManualDetailDtoList:   cloneDeep(this.tableData).map(item=>{
                      let obj = {
                          ...item,
                          dj: this.infoFormData.jems == '01'? item.bhsdj : item.hsdj,
                          je: this.infoFormData.jems == '01'? item.bhsje : item.sl * item.hsdj || item.sl * item.dj,
                          fphxz: '00',
                      }
                      return obj
                  }
              ),
              vmsManualExtendDto: {
                ...this.disabledEditForm,
                ...this.extendFormData,
                gmfzrrbz: this.infoFormData.gmfsfwzrr,
                sfzsgmfyhzhbq: this.extendFormData.sfzsgmfyhzhbq === true ? 'Y':"N",
                sfzsxsfyhzhbq: this.extendFormData.sfzsxsfyhzhbq === true ? 'Y':"N",
              },
              vmsManualTdywDtoList: this.$refs.componentSelectRef&&this.$refs.componentSelectRef.getFormValue() || []
          }

          console.log(obj2);



          let fn = checkAndSave
          if (this.from == 'look' || this.from == 'edit') {
              fn = updateInvoice
              obj2.vmsManualExtendDto.id = this.extendFormData.id
          } else {
              obj2.vmsManualBaseDto = {
                  ...obj2.vmsManualBaseDto,
                  ...this.disabledEditForm,
                  applyId:
                      this.$store.state.invoice2.invoinceFormStart1.busId,
              }
          }
          fn(obj2).then(
              (res) => {
                  this.$setLoading(false)
                  if (res.code === '200') {
                      k.$emit('refresh', {})
                      k.$refs.modal1.close()
                      this.$message.success(res.message)
                  } else if (res.code === '7012') {
                      this.msgShow = true
                      this.messageDialog = res.data
                  }
              },
              () => {
                  // this.$message.warning('接口异常')
                  this.$setLoading(false)
              }
          )
      },

      closeBox() {
          this.$refs.modal1.close()
      },
      detailCopy(d) {
        // 2222
          this.infoFormData = d.vmsManualBaseVo
          this.infoFormData.gmfsfwzrr = d.vmsManualExtendVo.gmfzrrbz

          let jems = this.infoFormData.jems // 01不含税 02含税

          this.extendFormData = d.vmsManualExtendVo; 
        //   // 之前是true,false, 改成Y或者N
          this.extendFormData.sfzsxsfyhzhbq = d.vmsManualExtendVo.sfzsxsfyhzhbq === "Y"?true:false
          this.extendFormData.sfzsgmfyhzhbq = d.vmsManualExtendVo.sfzsgmfyhzhbq === "Y"?true:false


          this.fjysList = d.vmsManualAddVoList || []
          this.maxId = d.length

          this.disabledEditForm = {
              xsfdz: d.vmsManualExtendVo.xsfdz,
              xsfzh: d.vmsManualExtendVo.xsfzh,
              xsfkhh: d.vmsManualExtendVo.xsfkhh,
              xsfdh: d.vmsManualExtendVo.xsfdh,
              qydm: d.vmsManualExtendVo.qydm,

              xsfmc: d.vmsManualBaseVo.xsfmc,
              xsfnsrsbh: d.vmsManualBaseVo.xsfnsrsbh,
              hydm: d.vmsManualBaseVo.hydm,
              kpr: d.vmsManualBaseVo.kpr,
          }
          this.vmsManualTdywDtoList = d.vmsManualTdywVoList; // 初始化会先清空, 异步加载
          



          setTimeout(()=>{
                this.tableData = d.vmsManualDetailVoList.map((voi) => { // 
                    return {
                        ...voi,
                        bhsdj:
                            jems == '01'
                                ? voi.dj
                                : voi.je / (1 + voi.slv) / voi.hsdj / (1 + voi.slv),
                        bhsje: jems == '01' ? voi.je : voi.je / (1 + voi.slv),
                        hsdj: voi.hsdj,
                        hsje: jems == '02' ? voi.je : voi.je * (1 + voi.slv),
                    }
                })
          },500)

      },
      show(from, row) {
          this.from = from
          if (from == 'look' || from == 'edit') {
              this.resetData()
              setTimeout(() => {
                    this.detailCopy(row)
                  this.$refs.modal1.open()
                  this.$nextTick(() => {
                      this.$refs.modal1.maximize()
                  })
              }, 200)
          } else if (from == 'red') {
              this.resetData()
              this.billCode = row
              this.getRedData()
          } else {
              this.resetData()
              this.addDetailCopy()
              this.$refs.modal1.open()
              this.$nextTick(() => {
                  this.$refs.modal1.maximize()
              })
          }
      },
  },

}
</script>
<style lang="scss" scoped>
:v-deep .vxe-table--render-default .vxe-header--column:not(.col--ellipsis) {
  padding: 0;
}

input::-ms-clear {
  width: 0;
  height: 0;
}
.invoice-area {
  position: relative;
  width: 900px;
  margin: 0 auto;
  display: flex;
  justify-content: flex-start;
  align-items: center;
  flex-wrap: wrap;
}
.box1 {
  width: 28px;
  height: 105px;
  opacity: 1;
  box-sizing: border-box;
  border: 1px solid #bb8c91;
  color: #bb8c91;
  border-right: none;
  display: flex;
  justify-content: center;
  align-items: center;
}
.box2 {
  width: 420px;
  height: 105px;
  opacity: 1;
  box-sizing: border-box;
  border: 1px solid #bb8c91;
  border-right: none;
  color: #bb8c91;
  display: flex;
  justify-content: center;
  align-items: center;
  flex-direction: column;
}
.box3 {
  width: 28px;
  height: 105px;
  opacity: 1;
  box-sizing: border-box;
  border: 1px solid #bb8c91;
  color: #bb8c91;
  border-right: none;
  display: flex;
  justify-content: center;
  align-items: center;
}
.box4 {
  width: 420px;
  height: 105px;
  opacity: 1;
  box-sizing: border-box;
  border: 1px solid #bb8c91;
  color: #bb8c91;
  display: flex;
  justify-content: center;
  align-items: center;
  flex-direction: column;
}
.box5 {
  width: 896px;
  height: 262px;
  min-height: 190px;
  opacity: 1;
  box-sizing: border-box;
  border: 1px solid #bb8c91;
  border-top: none;
  border-bottom: none;
}
.box6 {
  width: 240px;
  height: 32.2px;
  opacity: 1;
  box-sizing: border-box;
  border: 1px solid #bb8c91;
  border-right: none;
  color: #bb8c91;
  text-align: center;
  line-height: 32.2px;
}
.box7 {
  width: 656px;
  height: 32.2px;
  opacity: 1;
  box-sizing: border-box;
  border: 1px solid #bb8c91;
  display: flex;
  justify-content: flex-start;
  align-items: center;
  color: #bb8c91;
}
.boxSevenPointfive{
  // height: 500px;
  width: 896px;
}
.box8 {
  width: 28px;
  height: 120px;

  // height: 73.5px;
  opacity: 1;
  box-sizing: border-box;
  border: 1px solid #bb8c91;
  border-right: none;
  border-top: none;
  display: flex;
  justify-content: center;
  align-items: center;
  color: #bb8c91;
}
.box9 {
  width: 868px;
  height: 120px;
  opacity: 1;
  box-sizing: border-box;
  border: 1px solid #bb8c91;
  color: #bb8c91;
  overflow-y: auto;
  white-space:inherit;

  .zulinFormClass{
      margin:12px  12px 0;
      box-sizing: border-box;
  }
}
.bar-tit {
  width: 20px;
  display: inline-block;
  text-align: center;
}
.flex-invoice {
  display: flex;
  justify-content: flex-start;
  align-items: center;
  padding: 5px 0px;
  width: 400px;
}
.input {
  flex: 1;
}
.invoice-area .vxe-table--header-wrapper,
.invoice-area .vxe-header--row,
.invoice-area .vxe-table--header {
  background-color: #fff;
  color: #bb8c91;
  font-size: 12px;
  font-weight: normal;
  text-align: center;
}
.invoice-area .vxe-table--render-default .vxe-cell {
  font-size: 12px;
  font-weight: normal;
  text-align: center;
}
.gray {
}
.row {
  box-sizing: border-box;
  height: 24.5px;
  display: inline-block;
  line-height: 24.5px;
  margin-bottom: 5px;
}
.invoice-area
  .vxe-table--render-default.vxe-editable.size--mini
  .vxe-body--column,
.invoice-area
  .vxe-table--render-default.size--mini
  .vxe-header--column.col--ellipsis,
.invoice-area
  .vxe-table--render-default.size--mini
  .vxe-body--column.col--ellipsis,
.invoice-area
  .vxe-table--render-default.size--mini
  .vxe-footer--column.col--ellipsis {
  height: 24.5px;
  line-height: 24.5px;
}
.table-area-invoice {
  padding-left: 10px;
  height: 240px;
  overflow: auto;
  min-height: 160px;
  position: relative;
}
.col-red {
  color: #bb8c91;
}
.total-tit {
  color: #bb8c91;
}
.total-val {
  color: #bb8c91;
  display: inline-block;
  width: 40%;
  white-space: normal;
}
.remark {
  padding: 10px;
  display: inline-block;
}
.search-box {
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.red {
  color: #ea0000;
}
.info {
  width: 900px;
  margin: 0 auto;
}
.info-top {
  display: flex;
  justify-content: space-between;
  align-items: start;
}
.radio-tit {
  font-weight: bold;
}
.radio-item {
  margin-right: 20px;
  cursor: pointer;
}
.radio-icon {
  width: 15px;
  height: 15px;
  margin-right: 6px;
}
.box9 textarea {
  width: 100%;
  height: 100%;
  color: #bb8c91;
  border: none;
}
.man-area {
  margin-top: 12px;
  // margin-left: 60px;
}
.man-input {
  color: #bb8c91;
}
.add-fj {
  margin-right: 15px;
  cursor: pointer;
  color: #68d3cd;
}
.del-fj {
  cursor: pointer;
  color: #68d3cd;
}
.fj-area {
  margin-top: 10px;
  margin-bottom: 20px;
}
.form-tit {
  height: 14px;
  border-left: 3px solid #07b9b9;
  color: #1a1a1a;
  font-size: 12px;
  line-height: 14px;
  padding-left: 8px;
  font-weight: bold;
  width: 600px;
}

:deep .vxe-modal--wrapper .vxe-modal--box {
  overflow: auto;
}
:deep .vxe-modal--box {
  overflow: auto;
}
</style>
